import actionTypes from './actionTypes';
import { getAllNotifications } from '../requests';
export const startNotificationsLoading = () => {
  return {
    type: actionTypes.START_NOTIFICATIONS_LOADING
  };
};
export const finishNotificationsLoading = () => {
  return {
    type: actionTypes.FINISH_NOTIFICATIONS_LOADING
  };
};
//以上两个是可以共用的dispatch
export const markNotificationsAsReadById = id => dispatch => {
  dispatch(startNotificationsLoading());
  setTimeout(() => {
    dispatch({
      //模拟异步请求
      type: actionTypes.MARK_NOTIFICATIONS_AS_READ_BY_ID,
      payLoad: {
        id
      }
    });
    dispatch(finishNotificationsLoading());
  }, 1500);
};
export const markAllNotificationsAsRead = () => dispatch => {
  dispatch(startNotificationsLoading());
  setTimeout(() => {
    dispatch({
      type: actionTypes.MARK_ALL_NOTIFICATIONS_AS_READ
    });
    dispatch(finishNotificationsLoading());
  }, 1500);
};
export const getNotificationsList = () => dispatch => {
  dispatch(startNotificationsLoading());
  getAllNotifications().then(res => {
    if (res.code === 200) {
      dispatch({
        type: actionTypes.FINISH_GET_ALL_NOTOFICATIONS,
        payLoad: {
          list: res.data.list
        }
      });
    }
    dispatch(finishNotificationsLoading());
  });
};
